import request from "@/utils/request";

// 密码登录
export function login(data) {
  return request({
    url: "/system/login",
    method: "post",
    data: data,
  });
}

// 手机号短信登录
export function phoneLogin(data) {
  return request({
    url: "/phoneLogin",
    method: "post",
    data: data,
  });
}

// 登录发送短信
export function phoneCaptcha(userName) {
  return request({
    url: `/phoneCaptcha/${userName}`,
    method: "get",
  });
}

// 找回密码发送短信
export function byPhone(userName) {
  return request({
    url: `/forgetPassword/byPhone/${userName}`,
    method: "get",
  });
}
// 找回密码发送邮箱
export function byMail(email) {
  return request({
    url: `forgetPassword/byMail/${email}`,
    method: "get",
  });
}

// 校验验证码
export function checkPhone(data) {
  return request({
    url: `/forgetPassword/checkPhone`,
    method: "post",
    data
  });
}

// 校验邮箱验证码
export function checkMail(data) {
  return request({
    url: `/forgetPassword/checkMail`,
    method: "post",
    data
  });
}

// 找回密码发送短信
export function resetPwdByForgetPassword(data) {
  return request({
    url: `/sysUser/resetPwdByForgetPassword`,
    method: "put",
    data
  });
}

// 获取用户菜单
export function findCurrentUserTree() {
  return request({
    url: `/system/currentMenuTree`,
    method: "get",
  });
}

// 注册方法
export function register(data) {
  return request({
    url: "/register",
    headers: {
      isToken: false,
    },
    method: "post",
    data: data,
  });
}

// 获取用户详细信息
export function getInfo() {
  return request({
    url: "/system/userInfo",
    method: "get",
  });
}

// 退出方法
export function logout() {
  return request({
    url: "/system/logout",
    method: "post",
  });
}

// 获取验证码
export function getVerifyCodeImg() {
  return request({
    url: "/imgCaptcha",
    method: "get",
    timeout: 20000,
  });
}

// 修改密码
export function changePassWord(data) {
  return request({
    url: "/sysUser/resetPwd",
    method: "put",
    data
  })
}

// 判断密码是否在有效期内
export function findIsForceResetPwd() {
  return request({
    url: "/sysUser/findIsForceResetPwd",
    method: "get"
  })
}

// 强制修改自己密码
export function resetPwdBySelf(data) {
  return request({
    url: "/sysUser/resetPwdBySelf",
    method: "put",
    data
  })
}

export function findCurrentUserRole() {
  return request({
    url: '/sysUserRole/findCurrentUserRole',
    method: 'get'
  })
}

export function changeRoleApi(data) {
  return request({
    url: '/sysUserRole/changeRole',
    method: 'post',
    data
  })
}


export function ssoApi(key) {
  return request({
    url: '/sso/login?key=' + key,
    method: 'post',
  })
}

